package day5;

import java.util.Arrays;
import java.util.Random;

public class homework {
    public static void main(String[] args) {


        //2.a
        Random random = new Random();
        char[] charnum=new char[4];
        String[] charnumall= new String[5];

        for (int i = 0; i < 5; i++) {
            String s="";
            for (int j = 0; j < 4; j++) {
                int randomNumber = random.nextInt(26) + 97; // 生成1到10的随机数
                char randomChar = (char) randomNumber;
                //charnum[j]=randomChar;
                s=s+randomChar;
            }
            //charnumall[i] = new String(charnum);
            charnumall[i] = s;
        }
            System.out.println("随机数组:"+Arrays.toString(charnumall));


        //2.b
        int[] a={9,3,6,4,7,5};
        int[] b={13,1,16,7,14,2};
        int[] c=new int[a.length+b.length];
        System.out.println("原数组a:"+Arrays.toString(a));
        System.out.println("原数组b:"+Arrays.toString(b));
        for (int i = 0; i < a.length; i++) {
            c[i]=a[i];
        }
        for (int i = 0; i < b.length; i++) {
            c[i+ a.length]=b[i];
        }
        for(int i=0;i<c.length-1;i++){
            for(int j=0;j<c.length-1-i;j++){
                if(c[j]>c[j+1]){
                    c[j]=c[j]^c[j+1];
                    c[j+1]=c[j]^c[j+1];
                    c[j]=c[j]^c[j+1];
                }
            }
        }
        System.out.println("合并后数组升序："+Arrays.toString(c));


        //3.a
        int[][] d = new int[4][4];
        d[0][0]=1;
        for (int  i= 0; i < 3; i++) {
            d[i+1][0]=d[i][0]+1;
        }
        for(int i=0;i<4;i++){
            for (int j = 0; j < 3; j++) {
            d[i][j+1]=d[i][j]+1;
            }
        }
        System.out.println("二维数组:");
        System.out.println(Arrays.toString(d[0]));
        System.out.println(Arrays.toString(d[1]));
        System.out.println(Arrays.toString(d[2]));
        System.out.println(Arrays.toString(d[3]));


        //3.b
        int[] nums1={1,7,8,9,3};








        //3.b
        int[] nums={-1,-3,-1,9,1};
        int[] newNums=Arrays.copyOf(nums,nums.length);
        int temp=0;
        for(int i=0;i<nums.length-1;i++){
            for(int j=0;j<nums.length-1-i;j++){
                if(nums[j]>nums[j+1]){
                    nums[j]=nums[j]^nums[j+1];
                    nums[j+1]=nums[j]^nums[j+1];
                    nums[j]=nums[j]^nums[j+1];
                }
            }
        }
        System.out.println(Arrays.toString(nums));
        for (int i = nums.length-1; i >0; i--) {
            if(nums[nums.length-1]>nums[i-1]){
                System.out.println(nums[i-1]);
                temp=nums[i-1];
                for (int j=0;j<nums.length;j++) {
                    if (temp == newNums[j]) {
                        System.out.println("下标:" + j);
                    }
                }
                break;
            }
        }
    }
    public static int findTwo(int[] nums) {
        int one=nums[0];
        int indexone=0;
        int indextwo=0;
        int two=Integer.MIN_VALUE;
        for (int i=1; i<nums.length; i++) {
            if (nums[i]>one){
                two=one;
                one=nums[i];
                indextwo=indexone;
                indexone=i;
            }
            else if (nums[i]<one){
                two=nums[i];
                indextwo=i;
            }
        }
        System.out.println("第二大"+two);
        return indextwo;
    }
}
